package com.yd.mvc.mobile.MessageGroupController;

import com.yd.app.service.pc.messageGroupService.MessageGroupService;
import com.yd.app.service.sys.UserService;
import com.yd.app.util.BusinessException;
import com.yd.domain.commom.PageModel;
import com.yd.domain.searchParam.MessageGroupSearchParam;
import com.yd.domain.sys.DicEnum;
import com.yd.domain.sys.MessageGroup;
import com.yd.domain.sys.User;
import com.yd.mvc.baseController.BaseController;
import com.yd.mvc.baseController.util.AuthUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.util.Date;
import java.util.UUID;

/**
 * Created by Administrator on 2018/6/5.
 */
@RestController
@RequestMapping(value = "/mapi/msgGroup")
public class MMessageGroupController extends BaseController {
    @Autowired
    MessageGroupService messageGroupService;
    @Autowired
    UserService userService;
    /**
     * @Author: zy
     * @Desc: 查询未读消息
     * @Date:  2018/6/6
     * @Param
     */
    @RequestMapping(value = "/getNoReadQF", method = RequestMethod.GET)
    public int getNoReadQF(HttpServletRequest request) throws BusinessException {
        HttpSession session = request.getSession();
        User u = (User) session.getAttribute("login_user");
        int count=0;
        if(u!=null){
            count=messageGroupService.getNoReadQF(u.getId());
        }else{
            throw new BusinessException(401,"尚未登录","no-login");
        }
        return count;
    }
    /**
     * @Author: zy
     * @Desc: 条件分页查询已读未读
     * @Date:  2018/6/6
     * @Param
     */
    @RequestMapping(value = "/list/{pageIndex}/{pageSize}", method = RequestMethod.POST)
    public PageModel getCusQFMsg(@RequestBody MessageGroupSearchParam param, @PathVariable("pageIndex")int pageIndex, @PathVariable("pageSize")int pageSize,HttpServletRequest request)throws Exception {
        HttpSession session = request.getSession();
        User u = (User) session.getAttribute("login_user");
        PageModel pm=null;
        if(u!=null){
            param.setUserId(u.getId());
            pm=messageGroupService.getCusQFMsg(param,pageIndex,pageSize);
        }else{
            throw new BusinessException(401, "未登录");
        }
        return pm;
    }
    /**
     * 客户端删除操作---其实也是修改是否显示状态
     * @throws Exception
     */
    @RequestMapping(value = "/delete/{id}", method = RequestMethod.GET)
    public void updateIfShow(@PathVariable("id") String id,HttpServletRequest request)throws Exception {
        HttpSession session = request.getSession();
        User u = (User) session.getAttribute("login_user");
        if(u!=null){
            messageGroupService.deleteQf(id,u.getId());
        }else{
            throw new BusinessException(401, "未登录");
        }
    }
    /**
     * 客户端已读消息---修改已读未读状态
     * @throws Exception
     */
    @RequestMapping(value = "/updateRead/{id}", method = RequestMethod.GET)
    public void updateRead(@PathVariable("id") String id,HttpServletRequest request)throws Exception {
        HttpSession session = request.getSession();
        User u = (User) session.getAttribute("login_user");
        if(u!=null){
            messageGroupService.updateRead(id,u.getId());
        }else{
            throw new BusinessException(401, "未登录");
        }
    }
}
